/*
 * @Author: zhang_wenjuan
 * @Date: 2021-01-18 13:58:21
 * @LastEditTime: 2021-08-20 15:37:56
 * @Description: 运维模块
 */
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import 'vant/lib/index.css'
// rem h5 适配
import 'amfe-flexible/index.js'
/* 签名 */
import vueEsign from 'vue-esign'
//饼图 柱状图
import * as echarts from 'echarts';
import Utils from '@/utils/util'
import {
  Search,Row,Col,Panel,NavBar,IndexBar,IndexAnchor,Tab,Tabs,Toast,
  PullRefresh,List,Cell,CellGroup,Tabbar,TabbarItem,Icon,Overlay,Popup,Button,Picker,
  Loading,Uploader,Swipe,SwipeItem,Lazyload,Divider,NumberKeyboard,Collapse,CollapseItem,Dialog,
  DatetimePicker,Field,DropdownItem,DropdownMenu,CheckboxGroup,Checkbox,Circle,ActionSheet,SwipeCell,SwitchCell,
  RadioGroup,Radio,Notify,ImagePreview,Skeleton,Grid,GridItem,Tag,Image,NoticeBar,Popover,ShareSheet,Switch,Step,Steps 
} from 'vant'
let comps = [
  Search,Row,Col,Panel,NavBar,IndexBar,IndexAnchor,Tab,Tabs,Toast,
  PullRefresh,List,Cell,CellGroup,Tabbar,TabbarItem,Icon,Overlay,Popup,Button,Picker,
  Loading,Uploader,Swipe,SwipeItem,Lazyload,Divider,NumberKeyboard,Collapse,CollapseItem,Dialog,
  DatetimePicker,Field,DropdownItem,DropdownMenu,CheckboxGroup,Checkbox,Circle,ActionSheet,SwipeCell,SwitchCell,
  RadioGroup,Radio,Notify,ImagePreview,Skeleton,Grid,GridItem,Tag,Image,NoticeBar,Popover,ShareSheet,Switch,Step,Steps 
]
for (let comp of comps) {
  Vue.use(comp)
}

Vue.use(vueEsign)

Vue.config.productionTip = false
Vue.prototype.$Toast = Toast
Vue.prototype.$Dialog = Dialog
Vue.prototype.$echarts = echarts
Vue.prototype.$pageBack = Utils.baseUtil.pageBack

let vConsole = document.createElement('script');
vConsole.setAttribute('type', 'text/javascript');
vConsole.setAttribute('src', './static/vConsole.js');
document.body.appendChild(vConsole);

if (Utils.baseUtil.isPcOrMobile() == 'pc') {
  /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      store,
      render: h => h(App)
    })
  } else {
    // 添加cordova.js
    let cordovaScript = document.createElement('script');
    cordovaScript.setAttribute('type', 'text/javascript');
    cordovaScript.setAttribute('src', './static/cordova.js');
    document.body.appendChild(cordovaScript);
    document.addEventListener('deviceready', function() {
      console.log("tour Module deviceready")
      // 获取用户默认班组、变电站选择内容
      // Utils.baseUtil.getUserInfo(function (userInfo){
      //   //console.log("用户信息" + JSON.stringify(userInfo))
      //   if (!Utils.baseUtil.isEmptyString(userInfo.user)){
      //     localStorage.setItem("user", JSON.stringify(userInfo.user))
      //     localStorage.setItem("userId", userInfo.user.userId)
      //     localStorage.setItem("unitId", userInfo.user.unitId)
      //     localStorage.setItem("token", userInfo.user.sessionId)
      //     localStorage.setItem("loginName", userInfo.user.loginName)
      //   }
      //   if (!Utils.baseUtil.isEmptyString(userInfo.orgId)) {
      //     localStorage.setItem("orgId", userInfo.orgId)
      //     localStorage.setItem("orgName", userInfo.orgName)
      //   }
      //   if (!Utils.baseUtil.isEmptyString(userInfo.substationId)) {
      //     localStorage.setItem("DEFAULT_SUBSTATION_ID", userInfo.substationId)
      //     localStorage.setItem("DEFAULT_SUBSTATION_NAME", userInfo.substationName)
      //   }

        new Vue({
          el: '#app',
          router,
          store,
          render: h => h(App)
        })
        
      })
      document.addEventListener('backbutton', function() {
        console.log("backbutton")
        Toast.clear()
        // 后期物理退出按钮点击直接提示退出当前模块
        Dialog.confirm({
          message: '确定退出当前模块?'
        }).then(() => {
          //调用插件关闭当前webview，即可实现退出当前模块
          tpf.platformclient.goHome(function (data) {
            console.log('返回成功' + data)
          }, function (err) { })
        }).catch(() => {
          console.log("取消退出")
        })
      }, false);
}
